﻿package 
{
    import Activities.*;
    import com.assist.server.*;
    import com.assist.view.interfaces.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;

    public class Activities extends MovieClip implements IActivities
    {
        private const _priority:Array;
        private var _buttonEffect:Class;
        private var _activityData:Object;
        private var _activityList:Array;
        private var _tip:ITip;
        private var _activityVisible:Boolean = false;
        private var _onActivityStart:Function;
        private var _onActivityTimerClick:Function;
        private var _onDownTimeEnd:Function;
        private var _onMinute:Function;
        private var _diffTime:int = 0;
        private var _mcHeight:int = 82;
        private var _isAutoOpen:Boolean = false;
        private var _openFunction:OpenFunctionMc;
        private var _functionOpenPlayEnd:Function;
        private var _btnEffectData:Object;
        private var _xy:Array;
        private var _width:int = 0;
        private var _isScr:Boolean = false;

        public function Activities() : void
        {
            this._priority = [ActivityType.ActivityAward, FunctionType.Rune, ActivityType.FameRank, ActivityType.MissionRank, ActivityType.StatePointRank, ActivityType.CoinRank, FunctionType.PetAnimal, FunctionType.WorshipMars, FunctionType.GetPeach, FunctionType.RollCake, FunctionType.Furnace, TownType.DailyQuest, FunctionType.TakeBible, FunctionType.Farm, FunctionType.SuperSport, FunctionType.HeroMission, FunctionType.Tower, ActivityType.NineRegions, FunctionType.Zodiac, TownType.All, ActivityType.FactionAll, ActivityType.ServerWar, ActivityType.GameHelper];
            this._onActivityStart = new Function();
            this._onActivityTimerClick = new Function();
            this._onDownTimeEnd = new Function();
            this._onMinute = new Function();
            this._functionOpenPlayEnd = new Function();
            this._btnEffectData = {};
            this._xy = [720, 9];
            x = this._xy[0];
            y = this._xy[1];
            this._activityList = [];
            this._activityData = {};
            this._openFunction = new OpenFunctionMc();
            this._openFunction.functionOpenPlayEnd = function (param1:Object) : void
            {
                _functionOpenPlayEnd(param1);
                return;
            }// end function
            ;
            addChild(this._openFunction);
            return;
        }// end function

        public function clear() : void
        {
            var _loc_1:* = this._activityList.length;
            var _loc_2:* = _loc_1 - 1;
            while (_loc_2 >= 0)
            {
                
                this.removeActivity(this._activityList[_loc_2]);
                _loc_2 = _loc_2 - 1;
            }
            return;
        }// end function

        public function addActivity(param1:String) : void
        {
            var _loc_2:* = this._activityList.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                if (param1 == this._activityList[_loc_3])
                {
                    return;
                }
                _loc_3 = _loc_3 + 1;
            }
            this.loadActivity(param1);
            return;
        }// end function

        public function set onDownTimeEnd(param1:Function) : void
        {
            this._onDownTimeEnd = param1;
            return;
        }// end function

        public function set onMinute(param1:Function) : void
        {
            this._onMinute = param1;
            return;
        }// end function

        public function set diffTime(param1:int) : void
        {
            this._diffTime = param1;
            return;
        }// end function

        private function loadActivity(param1:String) : void
        {
            var type:* = param1;
            var obj:Object;
            var activityBtn:* = GetActivityButton.getActivityButton(type);
            addChild(activityBtn);
            activityBtn.buttonMode = true;
            var _downTimer:* = new ActivityDownTimer();
            activityBtn.addChild(_downTimer);
            _downTimer.x = 9;
            _downTimer.y = 68;
            _downTimer.isShowBtn = false;
            var effect:* = new this._buttonEffect();
            activityBtn.addChild(effect);
            effect.scaleY = 0.99;
            effect.y = -1;
            effect.visible = false;
            obj.buttonEffect = effect;
            obj.visibleEffect = false;
            obj.type = type;
            var textField:* = new TextField();
            obj.textField = textField;
            var textFormat:* = new TextFormat();
            obj.textFormat = textFormat;
            activityBtn.visible = this._activityVisible;
            _downTimer.onClick = function (param1:String) : void
            {
                _onActivityTimerClick(param1);
                return;
            }// end function
            ;
            _downTimer.onDownTimeEnd = function (param1:String) : void
            {
                _onDownTimeEnd(param1);
                return;
            }// end function
            ;
            _downTimer.onMinute = function (param1:String, param2:Number) : void
            {
                _onMinute(param1, param2);
                return;
            }// end function
            ;
            _downTimer.diffTime = this._diffTime;
            obj.mc = activityBtn;
            obj.isTip = false;
            obj.downTimer = _downTimer;
            obj.mouseClick = this.mouseClick(obj);
            obj.mouseOver = this.mouseOver(obj);
            obj.mouseOut = this.mouseOut(obj);
            obj.mc.addEventListener(MouseEvent.MOUSE_UP, obj.mouseClick);
            obj.mc.addEventListener(MouseEvent.MOUSE_OVER, obj.mouseOver);
            obj.mc.addEventListener(MouseEvent.MOUSE_OUT, obj.mouseOut);
            this._activityList.push(type);
            this._activityData[type] = obj;
            this.sortActivity();
            return;
        }// end function

        private function sortActivity() : void
        {
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            var _loc_8:int = 0;
            var _loc_1:* = [].concat(this._activityList);
            var _loc_2:Array = [];
            var _loc_3:* = this._priority.length;
            var _loc_4:* = _loc_3 - 1;
            while (_loc_4 > -1)
            {
                
                _loc_6 = _loc_1.indexOf(this._priority[_loc_4]);
                if (_loc_6 > -1)
                {
                    _loc_2 = _loc_2.concat(_loc_1.splice(_loc_6, 1));
                }
                _loc_4 = _loc_4 - 1;
            }
            _loc_2 = _loc_2.concat(_loc_1);
            var _loc_5:int = 0;
            _loc_3 = _loc_2.length;
            _loc_4 = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_7 = this._activityData[_loc_2[_loc_4]];
                if (_loc_7)
                {
                    _loc_8 = Math.floor(this._width / 100) - 3;
                    if (_loc_8 > 10)
                    {
                        _loc_8 = 10;
                    }
                    if (_loc_8 < 2)
                    {
                        _loc_8 = 2;
                    }
                    _loc_7.mc.x = Math.floor(-67 * (_loc_4 - Math.floor(_loc_4 / _loc_8) * _loc_8));
                    _loc_7.mc.y = Math.floor(this._mcHeight * Math.floor(_loc_4 / _loc_8));
                    if (_loc_7.type == ActivityType.ActivityFunction)
                    {
                        this._openFunction.x = -this.x;
                        this._openFunction.y = -this.y;
                        this._openFunction.setEndTarget = _loc_7;
                        addChild(this._openFunction);
                        if (this._isAutoOpen)
                        {
                            this._onActivityStart(_loc_7);
                        }
                    }
                }
                _loc_4 = _loc_4 + 1;
            }
            this._isScr = true;
            return;
        }// end function

        public function isAutoOpen(param1:Boolean) : void
        {
            this._isAutoOpen = param1;
            return;
        }// end function

        private function mouseClick(param1:Object) : Function
        {
            var obj:* = param1;
            var func:* = function (event:MouseEvent) : void
            {
                _onActivityStart(obj);
                return;
            }// end function
            ;
            return func;
        }// end function

        private function mouseOver(param1:Object) : Function
        {
            var data:* = param1;
            var func:* = function (event:MouseEvent) : void
            {
                data.mc.gotoAndStop(2);
                return;
            }// end function
            ;
            return func;
        }// end function

        private function mouseOut(param1:Object) : Function
        {
            var data:* = param1;
            var func:* = function (event:MouseEvent) : void
            {
                data.mc.gotoAndStop(1);
                return;
            }// end function
            ;
            return func;
        }// end function

        public function activityTimer(param1:String, param2:Object) : void
        {
            var _loc_5:Object = null;
            var _loc_3:* = this._activityList.length;
            var _loc_4:* = _loc_3 - 1;
            while (_loc_4 > -1)
            {
                
                if (this._activityList[_loc_4] == param1)
                {
                    _loc_5 = this._activityData[this._activityList[_loc_4]];
                    _loc_5.downTimer.isShowBtn = param2.showBtn;
                    _loc_5.downTimer.startTimerColor = param2.startTimerColor;
                    _loc_5.downTimer.endTimerColor = param2.endTimerColor;
                    _loc_5.downTimer.endTimerStr = param2.endTimerStr;
                    _loc_5.downTimer.mcType = param2.sendType;
                    _loc_5.downTimer.downTimer = param2.timer;
                    _loc_5.showBtn = param2.showBtn;
                    return;
                }
                _loc_4 = _loc_4 - 1;
            }
            return;
        }// end function

        public function playOpenFunctionMc(param1:Array) : void
        {
            this._openFunction.setFunctionList(param1);
            return;
        }// end function

        public function set functionOpenPlayEnd(param1:Function) : void
        {
            this._functionOpenPlayEnd = param1;
            return;
        }// end function

        public function hideActivityTimer(param1:String, param2:String) : void
        {
            var _loc_5:Object = null;
            var _loc_3:* = this._activityList.length;
            var _loc_4:* = _loc_3 - 1;
            while (_loc_4 > -1)
            {
                
                if (this._activityList[_loc_4] == param1)
                {
                    _loc_5 = this._activityData[this._activityList[_loc_4]];
                    if (_loc_5.downTimer.EndTimerStr == param2)
                    {
                        _loc_5.downTimer.isShowBtn = false;
                        _loc_5.buttonEffect.visible = false;
                        return;
                    }
                }
                _loc_4 = _loc_4 - 1;
            }
            return;
        }// end function

        public function isLoaderActivitie(param1:String) : Boolean
        {
            var _loc_2:* = this._activityList.length;
            var _loc_3:* = _loc_2 - 1;
            while (_loc_3 > -1)
            {
                
                if (this._activityList[_loc_3] == param1)
                {
                    return true;
                }
                _loc_3 = _loc_3 - 1;
            }
            return false;
        }// end function

        public function getActivityPoint(param1:String) : Point
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._activityList.length;
            var _loc_3:* = _loc_2 - 1;
            while (_loc_3 > -1)
            {
                
                _loc_4 = this._activityData[this._activityList[_loc_3]];
                if (this._activityList[_loc_3] == param1)
                {
                    return new Point(_loc_4.mc.x, _loc_4.mc.y);
                }
                _loc_3 = _loc_3 - 1;
            }
            return new Point(0, 0);
        }// end function

        public function autoActivityClick(param1:String) : void
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._activityList.length;
            var _loc_3:* = _loc_2 - 1;
            while (_loc_3 > -1)
            {
                
                _loc_4 = this._activityData[this._activityList[_loc_3]];
                if (this._activityList[_loc_3] == param1)
                {
                    this._onActivityStart(_loc_4);
                    return;
                }
                _loc_3 = _loc_3 - 1;
            }
            return;
        }// end function

        public function removeActivity(param1:String) : void
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._activityList.length;
            var _loc_3:* = _loc_2 - 1;
            while (_loc_3 > -1)
            {
                
                if (this._activityList[_loc_3] == param1)
                {
                    _loc_4 = this._activityData[this._activityList[_loc_3]];
                    removeChild(_loc_4.mc);
                    _loc_4.downTimer.parent.removeChild(_loc_4.downTimer);
                    _loc_4.downTimer.clear();
                    _loc_4.mc.removeEventListener(MouseEvent.MOUSE_UP, _loc_4.mouseClick);
                    _loc_4.mc.removeEventListener(MouseEvent.MOUSE_OVER, _loc_4.mouseOver);
                    _loc_4.mc.removeEventListener(MouseEvent.MOUSE_OUT, _loc_4.mouseOut);
                    if (_loc_4.isTip)
                    {
                        this._tip.removeTarget(_loc_4.mc);
                        _loc_4.isTip = false;
                    }
                    delete this._activityData[this._activityList[_loc_3]];
                    this._activityList.splice(_loc_3, 1);
                    break;
                }
                _loc_3 = _loc_3 - 1;
            }
            this.sortActivity();
            return;
        }// end function

        public function set activityVisible(param1:Boolean) : void
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._activityList.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = this._activityData[this._activityList[_loc_3]];
                _loc_4.mc.visible = param1;
                _loc_3 = _loc_3 + 1;
            }
            this._activityVisible = param1;
            this.refreshBtnEffect();
            return;
        }// end function

        public function visibleBtnEffect(param1:String, param2:String, param3:Boolean) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            var _loc_4:Object = {sign:param2, bool:param3};
            if (this._btnEffectData[param1])
            {
                _loc_5 = this._btnEffectData[param1];
                _loc_6 = _loc_5.length;
                _loc_7 = 0;
                while (_loc_7 < _loc_6)
                {
                    
                    _loc_8 = _loc_5[_loc_7];
                    if (_loc_8.sign == param2)
                    {
                        _loc_8.bool = param3;
                        this.renderBtnEffect(this._btnEffectData[param1], param1);
                        return;
                    }
                    _loc_7 = _loc_7 + 1;
                }
            }
            else
            {
                this._btnEffectData[param1] = [];
            }
            this._btnEffectData[param1].push(_loc_4);
            this.renderBtnEffect(this._btnEffectData[param1], param1);
            return;
        }// end function

        private function renderBtnEffect(param1:Array, param2:String) : void
        {
            var _loc_6:Object = null;
            var _loc_3:* = this._activityData[param2];
            if (_loc_3 == null)
            {
                return;
            }
            if (param1 == null)
            {
                _loc_3.buttonEffect.visible = false;
                return;
            }
            var _loc_4:* = param1.length;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4)
            {
                
                _loc_6 = param1[_loc_5];
                if (_loc_6.bool == true)
                {
                    _loc_3.buttonEffect.visible = this._activityVisible;
                    return;
                }
                _loc_5 = _loc_5 + 1;
            }
            _loc_3.buttonEffect.visible = false;
            return;
        }// end function

        private function refreshBtnEffect() : void
        {
            var _loc_3:String = null;
            var _loc_4:Array = null;
            var _loc_1:* = this._activityList.length;
            var _loc_2:* = _loc_1 - 1;
            while (_loc_2 > -1)
            {
                
                _loc_3 = this._activityList[_loc_2];
                _loc_4 = this._btnEffectData[_loc_3];
                this.renderBtnEffect(_loc_4, _loc_3);
                _loc_2 = _loc_2 - 1;
            }
            return;
        }// end function

        public function activityTip(param1:String, param2:String) : void
        {
            var _loc_5:Object = null;
            var _loc_3:* = this._activityList.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = this._activityData[this._activityList[_loc_4]];
                if (this._activityList[_loc_4] == param1)
                {
                    _loc_5.textField.textColor = 16777215;
                    _loc_5.textField.htmlText = param2;
                    _loc_5.textField.autoSize = TextFieldAutoSize.LEFT;
                    _loc_5.textFormat.leading = 8;
                    _loc_5.textField.setTextFormat(_loc_5.textFormat);
                    this._tip.addTarget(_loc_5.mc, _loc_5.textField);
                    _loc_5.isTip = true;
                    return;
                }
                _loc_4 = _loc_4 + 1;
            }
            return;
        }// end function

        public function set activityRuneNum(param1:int) : void
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._activityList.length;
            var _loc_3:* = _loc_2 - 1;
            while (_loc_3 > -1)
            {
                
                if (this._activityList[_loc_3] == FunctionType.Rune)
                {
                    _loc_4 = this._activityData[this._activityList[_loc_3]];
                    _loc_4.mc._Num._Count.text = param1;
                    return;
                }
                _loc_3 = _loc_3 - 1;
            }
            return;
        }// end function

        public function reposition(param1:int, param2:int, param3:int, param4:int, param5:Point) : void
        {
            x = Math.max(this._xy[0] - param5.x, Math.min(param3, stage.stageWidth) - (param1 - this._xy[0]));
            this._width = Math.max(param1, Math.min(param3, stage.stageWidth)) - param5.x;
            if (this._isScr)
            {
                this.sortActivity();
            }
            return;
        }// end function

        public function get content() : MovieClip
        {
            return this;
        }// end function

        public function set buttonEffect(param1:Class) : void
        {
            this._buttonEffect = param1;
            return;
        }// end function

        public function set tip(param1:ITip) : void
        {
            this._tip = param1;
            return;
        }// end function

        public function set onActivityTimerClick(param1:Function) : void
        {
            this._onActivityTimerClick = param1;
            return;
        }// end function

        public function set onActivityStart(param1:Function) : void
        {
            this._onActivityStart = param1;
            return;
        }// end function

    }
}
